import axios from "axios";
import {Message} from "element-ui";

/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 18-10-24
 * Time: 上午2:59
 * Description: requestWeb
 */


const serverService = axios.create({
  baseURL: process.env.SERVER_API, // api的base_url
  timeout: 5000 // request timeout
});


/**
 * 中心服务器接口拦截器
 */
serverService.interceptors.response.use(
  response => {
    if (response.data.code !== 200) {
      let error = response.data.message;
      console.log('err' + error);// for debug
      Message({
        message: error,
        type: 'error',
        duration: 2000
      });
      return Promise.reject(error);
    } else {
      return response.data
    }
  },
  error => {
    console.log('err' + error);// for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    });
    return Promise.reject(error);
  });

export default serverService;
